package com.zjh;

import com.zjh.bean.Student;

import java.util.ArrayList;
import java.util.List;

/**
 * @author LiZiQiu
 * @data 2023/3/5
 */
public class ThreadLocalTest {
    private ThreadLocal<String> threadLocal = new ThreadLocal();
    private List<String> list = new ArrayList();

    class A extends Thread {
        @Override
        public void run() {
            System.out.println("线程A开始存值");
            threadLocal.set("thread内容");
            list.add("list内容");
        }
    }

    class B extends Thread {
        @Override
        public void run() {
            try {
                Thread.sleep(2000);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            System.out.println("线程B开始取值");
            System.out.println("threadLocal：" + threadLocal.get());
            System.out.println("list：" + list.get(0));
        }
    }

    public static void main(String[] args) {
        ThreadLocalTest threadLocalTest = new ThreadLocalTest();
        ThreadLocalTest.A a =  threadLocalTest.new A();
        ThreadLocalTest.B b =  threadLocalTest.new B();


        a.start();
        b.start();



    }
}
